package com.leetcode.algorithm.y22.m09.w3;

import java.util.LinkedList;
import java.util.Queue;

import com.leetcode.algorithm.common.Node;

/**
 * 559. N 叉树的最大深度
 * 
 * https://leetcode.cn/problems/maximum-depth-of-n-ary-tree/
 * 
 * @author jie.deng
 *
 */
class Question0559Solution01 {

	public int maxDepth(Node root) {
		// BFS
		int level = 0;
		if (root == null) {
			return level;
		}
		Queue<Node> queue = new LinkedList<>();
		queue.add(root);

		while (!queue.isEmpty()) {
			level++;
			int len = queue.size();
			for (int i = 0; i < len; i++) {
				Node node = queue.poll();
				for (Node tmp : node.children) {
					queue.add(tmp);
				}
			}

		}

		return level;
	}
}